package net.oschina.archx.spring.sequoiadb.aop;

import net.oschina.archx.spring.sequoiadb.SequoiaFactory;
import org.aspectj.lang.annotation.*;

/**
 * 巨杉数据库工厂切面
 *
 * @author Archx
 * @date 2015/6/30 0030
 */
@Aspect
public class SequoiaFactoryAspect {

    private final SequoiaFactory sequoiaFactory;

    public SequoiaFactoryAspect(SequoiaFactory sequoiaFactory) {
        this.sequoiaFactory = sequoiaFactory;
    }

    @Pointcut(value = "@within(org.springframework.stereotype.Service)")
    public void contextPointcut() {
    }

    @Before(value = "contextPointcut()")
    public void beforeAdvice() throws InterruptedException {
        sequoiaFactory.getInstance();
    }

    @After(value = "contextPointcut()")
    public void afterAdvice() {
        sequoiaFactory.close();
    }
}
